import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { CreateMenuDto } from './dto/create.menu.dto';
import { FindAllMenuDto } from './dto/find-all-menu.dto';
import { UpdateMenuDto } from './dto/update.menu.dto';
import { MenuService } from './menu.service';

@Controller('menus')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Get('routes')
  listRoutes() {
    return this.menuService.listRoutes();
  }

  @Get('options')
  findOptions() {
    return this.menuService.findOptions();
  }

  @Get()
  findMenusTree(@Query() query: FindAllMenuDto) {
    return this.menuService.findMenusTree(query);
  }

  @Post()
  async create(@Body() body: CreateMenuDto) {
    await this.menuService.create(body);
    return '创建成功';
  }

  @Put(':id')
  async update(@Param('id') id: number, @Body() body: UpdateMenuDto) {
    await this.menuService.update(id, body);
    return '编辑成功';
  }

  @Delete(':id')
  async delete(@Param('id') id: number) {
    await this.menuService.delete(id);
    return '删除成功';
  }

  @Get(':id/form')
  async findForm(@Param('id') id: number) {
    return this.menuService.findForm(id);
  }
}
